<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css"
          href="css/jquery/jquery-ui-1.8.23.custom.css" media="screen"/>
    <script type="text/javascript" src="js/jquery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript"
            src="js/jquery/jquery-ui-1.8.23.custom.min.js"></script>
    <!-- <script type="text/javascript" src="js/test.js"></script> -->
    <script type="text/javascript">
        $(function () {
// 		$(':checkbox[name=flag]').each(function() {
// 			$(this).click(function() {
// 				if ($(this).attr('checked')) {
// 					if($("#agree").attr('checked')) {
// 						if($("#reject").attr('checked') && $("#aa").attr('checked')) {
// 							$(':checkbox[id=reject]').removeAttr('checked');
// 							$(':checkbox[id=aa]').removeAttr('checked');
// 							$(this).attr('checked', 'checked');
// 						} else {
// 							$(this).attr('checked', 'checked');
// 						}
// 					} else {
// 	 					$(':checkbox[name=flag]').removeAttr('checked');
// 	 					$(this).attr('checked', 'checked');
// 					}
// 				}
// 			});
// 		});

            $(':checkbox[name=containerType]').each(function () {
                $(this).click(function () {
                    $(':checkbox[name=containerType]').removeAttr('checked');
                    $(this).attr('checked', 'checked');
                });
            });

            $("#container").bind('keydown', function (event) {
                if (event.keyCode == 13) {
                    var container = "MRKU9028656";
                    var work_type = "0";
// 				var data = "container=";
                    $.ajax({
// 					url : "declaration-getContainerInfo",
                        url: "../gtimp/business/declaration-getContainerInfoVal",
                        cache: false,
                        dataType: "json",
// 					data : data,
                        success: function (data) {
                            var jdata = eval(data.containerInfo);
                            var output = "";
                            for (var i = 0; i < jdata.length; i++) {
                                var container = jdata[i].CONTAINER_NO;
                                var ct_size = jdata[i].CT_SIZE;
                                if (ct_size == "20") {
                                    ct_size = "S";
                                }
                                else {
                                    ct_size = "L";
                                }
                                output += "<tr><td><input type='checkbox' value='" + container + "' title='" + ct_size + "' /></td>";
                                output += "<td>" + container + "</td>";
                                output += "<td>" + ct_size + "</td>";
                                output += "</tr>";
                            }
                            output += "<tr><td>共" + jdata.length + "只柜</td>" +
                                    "<td><a href='javascript:doSelectCN(0)'>确定</a></td>" +
                                    "<td><a href='javascript:doSelectCN(-1)'>取消</a></td>" +
                                    "</tr>";
                            $("#cnListSelectTB").append(output);
                            $("#cnListSelectTB").show();
                        }
                    });
                }
            });

            $("#cnListSelectTB").hide();
        });

        function choseContainerType(type) {
            if (type == 'gh') {
            }
        }

        function selectAllCN() {
            $("#cnListSelectTB").find("input:checkbox").each(function () {
                if ($("#selectAllCN").attr("checked")) {
                    $(this).attr("checked", true);
                }
                else {
                    $(this).attr("checked", false);
                }
            });
        }

        function doSelectCN(flag) {
            if (flag == 0) {
                var fcn = "";
                var cnList = new Array();
                $("#guanbi").remove();
                $("#cnListTB").find("tr").each(function (index) {
                    if ($(this).attr("class") != "titleTR") {
                        cnList[index] = $(this).find("td")[1].innerText;
                    }
                });
                var exsitCnStr = "";
                var output = "";
                $("#cnListSelectTB").find("input:checkbox").each(function () {
                    if ($(this).attr("id") != "selectAllCN" && $(this).attr("checked")) {
                        var count = $("#cnListTB").find("tr").size();
                        var cn = $(this).val();
                        fcn = cn;
                        var CT_SIZE = $(this).attr("title");
                        // check cn
                        var cnExsit = false;
                        for (var ci = 0; ci < cnList.length; ci++) {
                            if (cn == cnList[ci]) {
                                cnExsit = true;
                            }
                        }
                        if (cnExsit) {
                            if (exsitCnStr.indexOf(cn) == -1) {
                                exsitCnStr += cn + " ";
                            }
                        }
                        else {
                            cnList[cnList.length] = cn;
                            output = "<tr>";
                            output += "<td class='cn_data_count' style=\"width:35px;\">" + count + "</td>";
                            output += "<td class='cn_data' style=\"width:180px;\">" + cn + "</td>";
                            output += "<td class='cn_data' style=\"width:60px;\">" + CT_SIZE + "</td>";
// 						output += "<td class='cn_data hiddenValue' style=\"width:80px;\">"+$("#weight_input").val()+"</td>";
// 						output += "<td class='hiddenValue'></td>";
                            output += "</tr>";
                            $("#cnListTB").append(output);
                            $("#cn_input").val("");
                            $("#specify_input").val("");
                            $("#weight_input").val("");

                            var test = $("#cnListTB").height() - $("#cn_input_content").height() + 40;
                            $("#cn_input_content").scrollTop(test);
                            $("#cnListTB").find("tr").each(function (index) {
                                if ($(this).attr("class") != "titleTR") {
                                    $(this).bind("click", function () {
                                        setTRClass("cnListTB", index, "selectTR");
                                        $("#cn_edit_no").attr("class", index);
                                        $(this).find("td").each(function (j) {
                                            data = $(this).text();
                                            switch (j) {
                                                case 1:
                                                    $("#cn_input").val(data);
                                                    $("#cn_input").focus();
                                                    break;
                                                case 2:
                                                    $("#specify_input").val(data);
                                                    break;
                                                case 3:
                                                    $("#weight_input").val(data);
                                                    break;
                                                default:
                                                    break;
                                            }
                                        });
                                    });
                                }
                            });
                        }
                    }
                });
                output = "<tr id='guanbi' class='titleTR'><td><a href='javascript:doClose()'>关闭</a></td></tr>"
                $("#cnListTB").append(output);
                if (exsitCnStr != "") {
                    alert("重复的柜号有：" + exsitCnStr);
                }
// 			getShipOwnerFromCN(fcn);
            }
            $("#cnListSelectTB").find("tr").each(function () {
                if ($(this).attr("class") != "titleTR") {
                    $(this).remove();
                }
            });
            $("#selectAllCN").attr("checked", false);
            $("#cnListSelectTB").hide();
            $("#cn_input").focus();
            prop_bathOutputStr = "";
        }

        function clearAllCN() {
            var delNO = $("#cn_del_no").attr("title");
            clearInput("cn");
            $("#cnListTB").find("tr").each(function (index) {
                if ($(this).attr("class") != "titleTR") {
                    $(this).remove();
// 				var cid = $("#cnListTB").find("td")[1].innerText;
// 				if(cid != "") {
// 					delNO += cid + "_";
// 				}
                }
            });
            $("#cn_del_no").attr("title", delNO);
        }


        function clearInput(type) {
            if (type == "cn") {
                $("#cn_edit_no").attr("class", 0);
                $("#cn_input").val("");
                $("#specify_input").val("");
                $("#weight_input").val("");

                $("#cnListTB").find("tr").each(function (index) {
                    if ($(this).attr("class") != "titleTR") {
                        $(this).unbind("click");
                    }
                });

                $("#cnListTB").find("tr").each(function (index) {
                    if ($(this).attr("class") != "titleTR") {
                        $(this).bind("click", function () {
                            setTRClass("cnListTB", index, "selectTR");
                            $("#cn_edit_no").attr("class", index);
                            var data = $(".cn_data")[index - 1].innerText;
                            $("#cn_input").val(data);
                            $("#cn_input").focus();
                        });
                    }
                });
            }
        }


        function test() {
            $.ajax({
//				url : "declaration-getContainerInfo",
                url: "../gtimp/test-test2",
                cache: false,
                dataType: "json",
                success: function (data) {
                    alert(2);
                }
            });
        }
    </script>
</head>
<body>

<!-- <input name="flag" id="agree" type="checkbox"  value="0"/> 同意  -->
<!-- <input name="flag" id="reject" type="checkbox" value="1" /> 不同意 -->
<!-- <input name="flag" id="aa" type="checkbox" value="1" /> 不同意 -->

<input type="button" value="测试" onclick="test();"/>

<input id="container" type="text"/>

<input name="containerType" id="guihuo" type="checkbox" onclick="choseContainerType('gh');"/> 柜货
<input name="containerType" id="sanhuo" type="checkbox" onclick="choseContainerType('sh');"/> 散货

<table id="cnListSelectTB" rules="rows" class="dataTB">
    <tr class="titleTR">
        <td><input type="checkbox" id="selectAllCN"
                   onclick="selectAllCN()" style="width: auto; margin-left: 5px;"/><label
                id="label_selectAllCN" for="selectAllCN">全选</label></td>
        <td>柜号</td>
        <td>相关单号</td>
    </tr>
</table>

<div id="cn_input_content"></div>
<div id="cn_edit_no" style="display: hidden;" class="0"></div>
<div id="cn_del_no" style="display: hidden;" title=""></div>

<table rules="rows" id="cnListTB" class="dataTB">
    <tr class="titleTR">
        <td class="titleTD" style="width: 35px;">序号</td>
        <td class="titleTD" style="width: 250px;">柜号<span
                id="clearAllCNSpan" style="margin-left: 30px;"><a
                href="javascript:clearAllCN();">全部清除</a></span>
			<span id="clearAllCNSpan_1" style="margin-left: 30px;"><a
                    href="javascript:clearAllCN_1();">关闭</a></span>
        </td>
        <td class="titleTD" style="width: 60px;">规格</td>
    </tr>
</table>


<div style="border: 1px">
    <table>
        <tr>
            <td>22222</td>
        <tr>
        <tr>
            <td>22222</td>
        <tr>
        <tr>
            <td>22222</td>
        <tr>
        <tr>
            <td>22222</td>
        <tr>
        <tr>
            <td>22222</td>
        <tr>
    </table>
    <table>
        <tr>
            <td>22222</td>
        <tr>
        <tr>
            <td>22222</td>
        <tr>
        <tr>
            <td>22222</td>
        <tr>
        <tr>
            <td>22222</td>
        <tr>
        <tr>
            <td>22222</td>
        <tr>
    </table>
</div>

</body>
</html>
